package com.example.lib5.queue.test;

/**
 * 创建日期：2022/6/3 0003 19:24
 *
 * @author tony.sun
 * 类说明：
 */
public class CircleQueue {
    public static void main(String[] args) {
        CircleQueueB circleQueueB = new CircleQueueB(4);
        circleQueueB.showQueue();
        circleQueueB.add(1);
        circleQueueB.add(2);
        circleQueueB.add(3);
        circleQueueB.add(4);
        circleQueueB.add(5);

    }
}
class CircleQueueB{
    private int maxSize;
    int[] arr;
    private int front;
    private int rear;
    public CircleQueueB(int maxSize) {
        this.maxSize=maxSize;
        arr=new int[maxSize];
    }

    public void showQueue() {
        if (isEmpty()){
            System.out.println("队列为空");
        }else {
            for (int i = front; i < rear+1; i++) {
                System.out.println(arr[i%maxSize]);
            }
        }
    }

    private int arrSize() {
        return 0;
    }

    private boolean isEmpty() {
        return false;
    }

    public void add(int i) {
        //判断队列是否已经满了
        if (isFull()){
            System.out.println("队列已满");
            return;
        }else {
            arr[front]=i;
            front++;
        }
    }

    private boolean isFull() {
        return rear+1-front==8;
    }
}
